Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
string-width
Advanced tools
Get the visual width of a string - the number of columns required to display it
The string-width npm package is used to calculate and return the visual width of a string - the number of columns required to display it. This is particularly useful when dealing with strings containing characters that may take up more than one column in terminals or monospaced fonts, such as emojis or certain international characters.
Calculate string width
This feature calculates the visual width of a string. For example, an ASCII character has a width of 1, while many CJK characters have a width of 2. Emojis can also have a width of 2 or more.
const stringWidth = require('string-width');
console.log(stringWidth('古')); // 2
console.log(stringWidth('a')); // 1
console.log(stringWidth('👍')); // 2
The wcwidth package is similar to string-width in that it provides functionality to determine the number of terminal column cells a wide-character string will occupy. It is based on the wcwidth() function defined in POSIX.1-2001 and POSIX.1-2008 which is used in Unix-based systems.
This package is designed to provide the functionality to determine the East Asian Width property as defined by Unicode. It can be used to figure out if a character is full-width, half-width, wide, narrow, ambiguous, or neutral. This is similar to string-width but focuses specifically on East Asian characters.
While string-width calculates the number of columns a string will take up in a monospaced font, string-pixel-width calculates the width of a string in pixels. This is useful for determining the actual rendered width of a string in a web page or an application with proportional fonts.
Get the visual width of a string - the number of columns required to display it
Some Unicode characters are fullwidth and use double the normal width. ANSI escape codes are stripped and doesn't affect the width.
Useful to be able to measure the actual width of command-line output.
$ npm install string-width
const stringWidth = require('string-width');
stringWidth('a');
//=> 1
stringWidth('古');
//=> 2
stringWidth('\u001B[1m古\u001B[22m');
//=> 2
FAQs
Get the visual width of a string - the number of columns required to display it
The npm package string-width receives a total of 124,349,062 weekly downloads. As such, string-width popularity was classified as popular.
We found that string-width demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.